// page_other/zdysbd/zdysbd.js
let app = getApp()
let yuming = app.globalData.yuming
let mobile = app.globalData.mobile
const request = require('../../config/request');
Page({
  ...request,
  /**
   * 页面的初始数据
   */
  data: {
    yuming: yuming,
    heights: "",
    title: "驻店药师绑定",
    buttonClicked: false,
    shopName: '',
    phone: '',
    isHave: -1,
    ysxx: '',
    jkzgq:'',
    zczgq:'',
  },
  phone(e) {
    this.setData({
      phone: e.detail.value
    })
  },
  check() {
    if (this.data.phone == '') {
      wx.showToast({
        title: '请输入手机号码',
        icon: 'none'
      })
    } else if (!mobile.test(this.data.phone)) {
      wx.showToast({
        title: '请输入正确的手机号码',
        icon: 'none'
      })
    } else {
      this.search()
    }
  },
  search() {
    let that = this;
    wx.showLoading({
      title: '查询中',
      icon: 'none'
    })
    this.myRequest(yuming + 'shop/shop_staff_yaoshi_seach', {
      shopId: wx.getStorageSync('shopIds'),
      mobile: that.data.phone
    }, 'POST').then(res => {
      wx.hideLoading();
      if (res.data.code == 200) {
        this.setData({
          ysxx: res.data.data,
          isHave: res.data.haveing,
          jkzgq:res.data.is_jainkang,
          zczgq:res.data.is_zhuce,
        })
      }
    })
  },
  //点击放大
  fangda(e) {
    console.log(e)
    var img = e.currentTarget.dataset.img
    wx.previewImage({
      urls: [img]
    })
  },
  ti() {
    if (this.data.ysxx == '') {
      wx.showToast({
        title: '请查询需要绑定的信息',
        icon: 'none'
      })
    } else if (this.data.ysxx == null) {
      wx.showToast({
        title: '需要绑定的信息不存在',
        icon: 'none'
      })
    }
    // else if (this.data.ysxx.Position != '驻店药师') {
    //   wx.showToast({
    //     title: '请绑定驻店药师',
    //     icon: 'none'
    //   })
    // } 
    else {
      this.bangding()
    }
  },
  bangding() {
    let that = this;
    that.setData({
      buttonClicked: true
    })
    this.myRequest(yuming + 'shop/shop_staff_yaoshi_bangding', {
      shopId: wx.getStorageSync('shopIds'),
      id: that.data.ysxx.id
    }, 'POST').then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        setTimeout(() => {
          wx.navigateTo({
            url: '/page_other/zdysdk/zdysdk?id=' + this.data.ysxx.id + '&shopId=' + wx.getStorageSync('shopIds'),
          })
        }, 1500)
      } else {
        that.setData({
          buttonClicked: false
        })
      }
    })
  },
  backs() {
    wx.navigateBack({
      delta: 0
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      shopName: wx.getStorageSync('shopname')
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },
})